Skip to content

Conversation

@nstilt1
Copy link

@nstilt1 nstilt1 commented Dec 22, 2025

Hey, I was experimenting with your code when I found that the stack_area() function includes an extra guard page in the usable size... unless I'm using it wrong? I believe that the stack area includes 2 guard pages and only 1 of them is subtracted. I have a test that fails, and switching it to subtract 2 guard pages fixes my test.

Fixes #134

@nstilt1
Copy link
Author

nstilt1 commented Dec 22, 2025

I see that cargo test --lib is not ran by the GitHub Actions. Also, it shouldn't break anything since requested_size is only used instead of the value returned by stack_area(), but it is mentioned in the comments here:

// TODO should we not pass `allocated_stack_size` here?
// TODO should we not pass `allocated_stack_size` here?
let panic = psm::on_stack(stack_base, requested_stack_size, move || {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(callback)).err()
Copy link
Author

@nstilt1 nstilt1 Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using allocated_stack_size could result in a segfault if the actual size is smaller than is reported by stack_area(), and if the stack overflows into these guard pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mmap stack_area() returns area that includes a guard page

1 participant